<template>
  <el-radio-group v-model="model" @change="change" v-bind="$attrs">
    <el-radio :label="value" v-for="{value, label} in radioOptions" :key="value">{{label}}</el-radio>
  </el-radio-group>
</template>

<script>
/**
 * 基于数据字典的下拉选择框
 */
import {mapGetters} from 'vuex'

export default {
  name: "DictSelect",
  props: {
    value: {
      type: [String, Number],
      default: ''
    },
    //字典类型
    dictKey: {
      type: String,
      required: false,
    },
    options: {
      type: Array,
      required: false,
    }
  },
  data() {
    return {
    }
  },
  computed: {
    ...mapGetters(['dictionary', 'dictionaryArr']),
    model:{
      get(){
        return this.value+''
      },
      set(value){
        this.$emit('input', value)
      }
    },
    radioOptions(){
      return this.dictionaryArr[this.dictKey] ? this.dictionaryArr[this.dictKey] : this.options;
    }
  },
  methods: {
    change(value){
      this.$emit('change', value)
    }
  }
}
</script>

<style scoped>

</style>
